package TangramBase;

import TangramCore.Poloha;
import TangramCore.Vzhled;
import java.awt.Paint;
import java.awt.Color;
import Pentominos.PentominosPanel;

public class PentominosConversion {
    
    private static final double sw = 1;
// public Poloha(double a, double x, double y, boolean f, int z)
    
    private static final int poradi[] = {-1,0,4,3,6,5,8,1,9,2,10,11,7};
    private static final Poloha p[][] = {
        {null},
        {// *** I ***
            new Poloha(90, 2.5*sw, 0.5*sw, false,0),
                    new Poloha(0, 0.5*sw, 2.5*sw,false,0)
        },
        {// *** X ***
            new Poloha(0, 0.5*sw, 1.5*sw, false,1)
        },
        {// *** Z ***
            new Poloha(0, 0.5*sw, 1.5*sw, false,2),
                    new Poloha(90,1.5*sw,1.5*sw,false,2),
                    new Poloha(0,1.5*sw,1.5*sw,true,2),
                    new Poloha(90,-0.5*sw,1.5*sw,true,2)
        },
        {// *** V ***
            new Poloha(90,1*sw,2*sw,false,3),
                    new Poloha(180,1*sw,1*sw,false,3),
                    new Poloha(0,0*sw,2*sw,false,3),
                    new Poloha(270,2*sw,1*sw,false,3)
        },
        {// *** T ***
            new Poloha(180,1.5*sw,1.5*sw,false,4),
                    new Poloha(270,-0.5*sw,1.5*sw,false,4),
                    new Poloha(0,0.5*sw,1.5*sw,false,4),
                    new Poloha(90,1.5*sw,1.5*sw,false,4)
        },
        {// *** W ***
            new Poloha(270,1*sw,2*sw,false,5),
                    new Poloha(180,0*sw,2*sw,false,5),
                    new Poloha(90,2*sw,1*sw,false,5),
                    new Poloha(0,0*sw,1*sw,false,5)
        },
        {// *** U ***
            new Poloha(90,1.5*sw,1*sw,false,6),
                    new Poloha(180,1*sw,1.5*sw,false,6),
                    new Poloha(270,1.5*sw,1*sw,false,6),
                    new Poloha(0,1*sw,1.5*sw,false,6)
        },
        {// *** L ***
            new Poloha(270,2*sw,1.5*sw,false,7),
                    new Poloha(180,0.5*sw,2*sw,false,7),
                    new Poloha(90,2*sw,0.5*sw,false,7),
                    new Poloha(0,0.5*sw,2*sw,false,7),
                    new Poloha(0,1.5*sw,2*sw,true,7),
                    new Poloha(270,2*sw,0.5*sw,true,7),
                    new Poloha(180,0.5*sw,2*sw,true,7),
                    new Poloha(90,-1*sw,1.5*sw,true,7)
        },
        {// *** N ***
            new Poloha(270,0*sw,1*sw,true,8),
                    new Poloha(180,1*sw,2*sw,true,8),
                    new Poloha(90,1*sw,1*sw,true,8),
                    new Poloha(0,1*sw,2*sw,true,8),
                    new Poloha(90,2*sw,1*sw,false,8),
                    new Poloha(0,0*sw,2*sw,false,8),
                    new Poloha(270,2*sw,1*sw,false,8),
                    new Poloha(180,0*sw,2*sw,false,8)
        },
        {// *** Y ***
            new Poloha(270,0.5*sw,1.5*sw,true,9),
                    new Poloha(180,0.5*sw,1.5*sw,true,9),
                    new Poloha(90,1.5*sw,0.5*sw,true,9),
                    new Poloha(0,0.5*sw,2.5*sw,true,9),
                    new Poloha(270,2.5*sw,0.5*sw,false,9),
                    new Poloha(180,0.5*sw,1.5*sw,false,9),
                    new Poloha(90,0.5*sw,1.5*sw,false,9),
                    new Poloha(0,0.5*sw,2.5*sw,false,9)
        },
        {// *** F ***
            new Poloha(90,0.5*sw,1.5*sw,false,10),
                    new Poloha(0,0.5*sw,1.5*sw,false,10),
                    new Poloha(270,1.5*sw,1.5*sw,false,10),
                    new Poloha(180,0.5*sw,1.5*sw,false,10),
                    new Poloha(90,-0.5*sw,1.5*sw,true,10),
                    new Poloha(0,1.5*sw,1.5*sw,true,10),
                    new Poloha(270,0.5*sw,1.5*sw,true,10),
                    new Poloha(180,0.5*sw,1.5*sw,true,10)
        },
        {// *** P ***
            new Poloha(180,1*sw,1*sw,false,11),
                    new Poloha(90,1*sw,1*sw,false,11),
                    new Poloha(0,1*sw,2*sw,false,11),
                    new Poloha(270,1*sw,1*sw,false,11),
                    new Poloha(90,1*sw,1*sw,true,11),
                    new Poloha(0,0*sw,2*sw,true,11),
                    new Poloha(270,2*sw,1*sw,true,11),
                    new Poloha(180,1*sw,1*sw,true,11)
        }
    };
    
    public static Vzhled getColoredVzhled(){
        Paint colors[] = new Paint[12];
        for(int i=1; i<=12; i++)
            colors[poradi[i]] = PentominosPanel.pieceColor[i];
        //return new Vzhled(null,Vzhled.a(null),colors);
        return new Vzhled(Vzhled.tenkyStroke,Vzhled.a(Color.black),colors);
    }
    
    public static Poloha[] convert(int rows, int cols, int sol[][]){
        Poloha pol[] = new Poloha[12];
        int notUsed = 0;
        double x = 1*sw, y = (rows+3)*sw;
        for(int i=1; i<=12; i++){
            //int orientace = p[i][0];
            //int row = p[i][1];
            //int col = p[i][2];
            int dilek = poradi[i];
            int orientace = sol[i][0];
            if(orientace == -1){
                pol[dilek] = new Poloha();
                pol[dilek].posunX = x;
                x+= 4*sw;
                pol[dilek].posunY = y;
                notUsed++;
                if(notUsed == 6){
                    x = 1 * sw;
                    y += 6;
                    notUsed = 0;
                }
            } else{
                pol[dilek] = new Poloha(p[i][orientace]);
                pol[dilek].posunX += sol[i][2] * sw;
                pol[dilek].posunY += sol[i][1] * sw;
            }
        }
        return pol;
    }
}
